<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>LeetCode_Hot_100 | jingxiao's space</title><meta name="author" content="jingxiao"><meta name="copyright" content="jingxiao"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="LeetCode 热题 100哈希1. 两数之和Map 把数组index作为value保存 49. 字母异位词分组hashmap.getOrDefault(Object key, V defaultValue) 获取指定 key 对应对 value，如果找不到 key ，则返回设置的默认值。把排序后相同str当作key 128. 最长连续序列Set 时间复杂度要求O(n)，那只有用空间来换时间，">
<meta property="og:type" content="article">
<meta property="og:title" content="LeetCode_Hot_100">
<meta property="og:url" content="https://jingxiao-yz.github.io/2023/05/04/LeetCode-Hot-100/index.html">
<meta property="og:site_name" content="jingxiao&#39;s space">
<meta property="og:description" content="LeetCode 热题 100哈希1. 两数之和Map 把数组index作为value保存 49. 字母异位词分组hashmap.getOrDefault(Object key, V defaultValue) 获取指定 key 对应对 value，如果找不到 key ，则返回设置的默认值。把排序后相同str当作key 128. 最长连续序列Set 时间复杂度要求O(n)，那只有用空间来换时间，">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://jingxiao-yz.github.io/img/default_cover.jpg">
<meta property="article:published_time" content="2023-05-04T12:14:51.000Z">
<meta property="article:modified_time" content="2023-08-09T15:57:13.841Z">
<meta property="article:author" content="jingxiao">
<meta property="article:tag" content="keywordssssssss">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://jingxiao-yz.github.io/img/default_cover.jpg"><link rel="shortcut icon" href="/img/favicon.ico"><link rel="canonical" href="https://jingxiao-yz.github.io/2023/05/04/LeetCode-Hot-100/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'LeetCode_Hot_100',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-08-09 23:57:13'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="jingxiao's space" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/head.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">3</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/default_cover.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="jingxiao's space"><span class="site-name">jingxiao's space</span></a></span><div id="menus"><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">LeetCode_Hot_100</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-05-04T12:14:51.000Z" title="发表于 2023-05-04 20:14:51">2023-05-04</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-08-09T15:57:13.841Z" title="更新于 2023-08-09 23:57:13">2023-08-09</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="LeetCode_Hot_100"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="LeetCode-热题-100"><a href="#LeetCode-热题-100" class="headerlink" title=" LeetCode 热题 100"></a><center> <a target="_blank" rel="noopener" href="https://leetcode.cn/studyplan/top-100-liked/">LeetCode 热题 100</a></center></h1><h2 id="哈希"><a href="#哈希" class="headerlink" title="哈希"></a><center>哈希</center></h2><h3 id="1-两数之和"><a href="#1-两数之和" class="headerlink" title="1. 两数之和"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/two-sum/?envType=study-plan-v2&id=top-100-liked">1. 两数之和</a></h3><p><strong>Map</strong> 把数组index作为value保存</p>
<h3 id="49-字母异位词分组"><a href="#49-字母异位词分组" class="headerlink" title="49. 字母异位词分组"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/group-anagrams/?envType=study-plan-v2&id=top-100-liked">49. 字母异位词分组</a></h3><p><strong><code>hashmap.getOrDefault(Object key, V defaultValue)</code></strong> 获取指定 key 对应对 value，如果找不到 key ，则返回设置的默认值。把排序后相同str当作key</p>
<h3 id="128-最长连续序列"><a href="#128-最长连续序列" class="headerlink" title="128. 最长连续序列"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/longest-consecutive-sequence/">128. 最长连续序列</a></h3><p><strong>Set</strong> 时间复杂度要求O(n)，那只有用空间来换时间，把数组转换到set里面来处理</p>
<h2 id="双指针"><a href="#双指针" class="headerlink" title="双指针"></a><center>双指针</center></h2><h3 id="15-三数之和"><a href="#15-三数之和" class="headerlink" title="15. 三数之和"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/3sum/?envType=study-plan-v2&id=top-100-liked">15. 三数之和</a></h3><ul>
<li><strong>先排序！先排序！先排序！</strong></li>
<li><strong><code>if(left &gt; 0 &amp;&amp; nums[left] == nums[left-1])</code></strong> 去重去重的前提是“当前数字，之前用过了，所以才跳过当前数字”；而不是因为 “后面有相同的当前数字，就不用当前数字”</li>
<li><strong><code>Arrays.asList(1，2，3)</code></strong> 把几个值转为一个list</li>
</ul>
<h3 id="283-移动零"><a href="#283-移动零" class="headerlink" title="283. 移动零"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/move-zeroes/">283. 移动零</a></h3><p>快慢指针，快指针遍历时，若不为0，将当前值fast赋给slow，slow加1，由于fast在前面，直接覆盖就是，由于是以fast为遍历索引，结束时注意填充尾部的0</p>
<h3 id="11-盛最多水的容器"><a href="#11-盛最多水的容器" class="headerlink" title="11. 盛最多水的容器"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/container-with-most-water/">11. 盛最多水的容器</a></h3><p>左右指针，向内靠拢，短边先动</p>
<h3 id="42-接雨水"><a href="#42-接雨水" class="headerlink" title="42. 接雨水"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/trapping-rain-water/">42. 接雨水</a></h3><p>对于每一列，找其出左右两边的最高列，当前列 一定会淹没在 它左边最高列和右边最高列构成的 凹槽 里面，找出水面高度（即较小的边），累加当前列对应的水量高度即可</p>
<h2 id="滑动窗口"><a href="#滑动窗口" class="headerlink" title="滑动窗口"></a><center>滑动窗口</center></h2><h3 id="3-无重复字符的最长子串"><a href="#3-无重复字符的最长子串" class="headerlink" title="3. 无重复字符的最长子串"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/longest-substring-without-repeating-characters/">3. 无重复字符的最长子串</a></h3><p>用 <strong>Set</strong> 来保存不同的值，快慢指针遍历比较，遇到相同的把slow的先去除</p>
<h3 id="438-找到字符串中所有字母异位词"><a href="#438-找到字符串中所有字母异位词" class="headerlink" title="438. 找到字符串中所有字母异位词"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/find-all-anagrams-in-a-string/">438. 找到字符串中所有字母异位词</a></h3><ul>
<li><strong>Arrays.equals(array1,array2)</strong> 判等</li>
<li>用字典保存字符串str所含字母信息：</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span>[] strdict = <span class="keyword">new</span> <span class="title class_">int</span>[<span class="number">26</span>];</span><br><span class="line"><span class="keyword">for</span>(<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; strlen; i++) strdict[str.charAt(i) - <span class="string">&#x27;a&#x27;</span>]++;</span><br></pre></td></tr></table></figure>

<p>维护一个相同长度的窗口字典，注意边界条件处理，移动窗口，左边的字母去掉，右边的字母加上，判断维护的两个字典数组是否相等</p>
<h2 id="字串"><a href="#字串" class="headerlink" title="字串"></a><center>字串</center></h2><h3 id="239-滑动窗口最大值"><a href="#239-滑动窗口最大值" class="headerlink" title="239. 滑动窗口最大值"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/sliding-window-maximum/?envType=study-plan-v2&id=top-100-liked">239. 滑动窗口最大值</a></h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 队列中保存下标，对应的数组数值从大到小排列，队首是窗口内最大值的下标</span></span><br><span class="line"><span class="keyword">while</span> (!zhan.isEmpty() &amp;&amp; nums[R] &gt;= nums[zhan.peekLast()])&#123;</span><br><span class="line">    zhan.removeLast();</span><br><span class="line">&#125;</span><br><span class="line">zhan.addLast(R);</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//用优先队列会超时，优先队列定义两种方式，优先队列内部只保证头部是最值，其它部分可能无序</span></span><br><span class="line">PriorityQueue&lt;Integer&gt; queue = <span class="keyword">new</span> <span class="title class_">PriorityQueue</span>&lt;Integer&gt;((a,b)-&gt;&#123;<span class="keyword">return</span> a-b;&#125;);</span><br><span class="line"></span><br><span class="line">PriorityQueue&lt;Integer&gt; queue = <span class="keyword">new</span> <span class="title class_">PriorityQueue</span>&lt;Integer&gt;(<span class="keyword">new</span> <span class="title class_">Comparator</span>&lt;Integer&gt;()&#123;</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">compare</span><span class="params">(Integer o1, Integer o2)</span>&#123;</span><br><span class="line">  <span class="keyword">return</span> o1.compareTo(o2); <span class="comment">//return o1 - o2;</span></span><br><span class="line"> &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<h3 id="560-和为-K-的子数组"><a href="#560-和为-K-的子数组" class="headerlink" title="560. 和为 K 的子数组"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/subarray-sum-equals-k/">560. 和为 K 的子数组</a></h3><p>前缀和</p>
<h2 id="普通数组"><a href="#普通数组" class="headerlink" title="普通数组"></a><center>普通数组</center></h2><h3 id="53-最大子数组和"><a href="#53-最大子数组和" class="headerlink" title="53. 最大子数组和"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/maximum-subarray/">53. 最大子数组和</a></h3><p><strong>贪心</strong>，遍历求和，如果当前的和小于0，不如直接重置当前和为当前数字；如果当前和大于0，直接继续加，相信美好的事情（变大）会发生，反正每轮都会判断</p>
<h3 id="56-合并区间"><a href="#56-合并区间" class="headerlink" title="56. 合并区间"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/merge-intervals/">56. 合并区间</a></h3><ul>
<li>二维数组排序，引入comparator，lambda表达式：<code>Arrays.sort(matrix,Comparator.comparingInt(arr -&gt; arr[0]));</code></li>
<li>list 转数组的 toArray()方法： <code>int[] resarray = listdemo.toArray(new int[listdemo.size()]);</code> 新建一个保存对象相同、数量大小相等的数组； 转二维同样适用，前提是listdemo里面的对象本来就是数组 <code>int[][] resarray = listdemo.toArray(new int[listdemo.size()][]);</code></li>
</ul>
<h3 id="189-轮转数组"><a href="#189-轮转数组" class="headerlink" title="189. 轮转数组"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/rotate-array/">189. 轮转数组</a></h3><p>用两个数组叠加，重新赋值，注意移位的可能大于数组长度</p>
<h3 id="238-除自身以外数组的乘积"><a href="#238-除自身以外数组的乘积" class="headerlink" title="238. 除自身以外数组的乘积"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/product-of-array-except-self/">238. 除自身以外数组的乘积</a></h3><p><strong>不能用除法，则不考虑前缀积</strong>，左右各遍历一下：第一次遍历，ans保存第i个数字其左侧<code>(0 ~ i-1)</code>的乘积；第二次遍历，当前ans值再乘上 第 i 个数字其右侧<code>(i+1 ~ len-1)</code>的总乘积 即为所求</p>
<h2 id="矩阵"><a href="#矩阵" class="headerlink" title="矩阵"></a><center>矩阵</center></h2><h3 id="73-矩阵置零"><a href="#73-矩阵置零" class="headerlink" title="73. 矩阵置零"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/set-matrix-zeroes/?envType=study-plan-v2&id=top-100-liked">73. 矩阵置零</a></h3><p>标记下标，用 <strong>Set</strong> 记录即可</p>
<h3 id="54-螺旋矩阵"><a href="#54-螺旋矩阵" class="headerlink" title="54. 螺旋矩阵"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/spiral-matrix/?envType=study-plan-v2&id=top-100-liked">54. 螺旋矩阵</a></h3><p>模拟即可，注意处理边界</p>
<h3 id="48-旋转图像"><a href="#48-旋转图像" class="headerlink" title="48. 旋转图像"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/rotate-image/">48. 旋转图像</a></h3><p>模拟即可，注意处理边界</p>
<h3 id="240-搜索二维矩阵-II"><a href="#240-搜索二维矩阵-II" class="headerlink" title="240. 搜索二维矩阵 II"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/search-a-2d-matrix-ii/">240. 搜索二维矩阵 II</a></h3><ul>
<li><strong>Z字形搜索</strong>，根据数学关系，从右上角开始搜索</li>
<li>深度搜索，类似求岛屿数量，遍历过的标记</li>
</ul>
<h2 id="链表"><a href="#链表" class="headerlink" title="链表"></a><center>链表</center></h2><h3 id="160-相交链表"><a href="#160-相交链表" class="headerlink" title="160. 相交链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/intersection-of-two-linked-lists/?envType=study-plan-v2&id=top-100-liked">160. 相交链表</a></h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//遍历到末尾 换另一条继续，两次过后长度一样</span></span><br><span class="line">A =  A != <span class="literal">null</span> ? A.next : headB;</span><br></pre></td></tr></table></figure>

<h3 id="206-反转链表"><a href="#206-反转链表" class="headerlink" title="206. 反转链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/reverse-linked-list/">206. 反转链表</a></h3><p>new一个<code>pre = null</code>方便操作</p>
<h3 id="234-回文链表"><a href="#234-回文链表" class="headerlink" title="234. 回文链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/palindrome-linked-list/">234. 回文链表</a></h3><ul>
<li>list保存值</li>
<li>先求出长度，再反转部分</li>
</ul>
<h3 id="141-环形链表"><a href="#141-环形链表" class="headerlink" title="141. 环形链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/linked-list-cycle/?envType=study-plan-v2&id=top-100-liked">141. 环形链表</a></h3><p>快慢指针，有环一定相遇，循环条件 <code>while(fast != slow)</code> 结束条件：<code>fast == slow //相遇了</code> 或 <code>fast = null //到末尾了，说明无环</code></p>
<h3 id="142-环形链表-II"><a href="#142-环形链表-II" class="headerlink" title="142. 环形链表 II"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/linked-list-cycle-ii/">142. 环形链表 II</a></h3><p>数学关系，快慢指针，注意第一次相遇后，fast从头部出发的时速度变为 1</p>
<h3 id="21-合并两个有序链表"><a href="#21-合并两个有序链表" class="headerlink" title="21. 合并两个有序链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/merge-two-sorted-lists/">21. 合并两个有序链表</a></h3><p>由于不知道长度，注意处理两条链表的开始和结束</p>
<h3 id="2-两数相加"><a href="#2-两数相加" class="headerlink" title="2. 两数相加"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/add-two-numbers/">2. 两数相加</a></h3><p>模拟加法过程即可</p>
<h3 id="19-删除链表的倒数第-N-个结点"><a href="#19-删除链表的倒数第-N-个结点" class="headerlink" title="19. 删除链表的倒数第 N 个结点"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/remove-nth-node-from-end-of-list/?envType=study-plan-v2&id=top-100-liked">19. 删除链表的倒数第 N 个结点</a></h3><p>快慢指针，快的先走n个，注意特殊情况判断</p>
<h3 id="24-两两交换链表中的节点"><a href="#24-两两交换链表中的节点" class="headerlink" title="24. 两两交换链表中的节点"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/swap-nodes-in-pairs/">24. 两两交换链表中的节点</a></h3><ul>
<li>建立虚拟头部节点，方便操作</li>
<li>构建 栈 用于改变方向；注意处理模拟的细节</li>
</ul>
<h3 id="25-K-个一组翻转链表"><a href="#25-K-个一组翻转链表" class="headerlink" title="25. K 个一组翻转链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/reverse-nodes-in-k-group/">25. K 个一组翻转链表</a></h3><p> 类似两两交换，引入计数量count即可</p>
<h3 id="138-复制带随机指针的链表"><a href="#138-复制带随机指针的链表" class="headerlink" title="138. 复制带随机指针的链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/copy-list-with-random-pointer/">138. 复制带随机指针的链表</a></h3><p><strong>Map</strong> key为原节点，value为新拷贝节点，第一遍创建拷贝，第二遍构建关系</p>
<h3 id="148-排序链表"><a href="#148-排序链表" class="headerlink" title="148. 排序链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/sort-list/?envType=study-plan-v2&id=top-100-liked">148. 排序链表</a></h3><p><strong>归并</strong>排序，递归调用，找到中间断开</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">ListNode</span> <span class="variable">slow</span> <span class="operator">=</span> head;</span><br><span class="line"><span class="type">ListNode</span> <span class="variable">fast</span> <span class="operator">=</span> head.next;</span><br><span class="line"><span class="keyword">while</span>(fast != <span class="literal">null</span> &amp;&amp; fast.next != <span class="literal">null</span>)&#123;</span><br><span class="line">    slow = slow.next;</span><br><span class="line">    fast = fast.next.next;<span class="comment">//两倍速度</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>后面合并的时候，注意可能有没比较完的</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">h.next = one != <span class="literal">null</span> ? one : two;<span class="comment">//合并时可能一段先遍历完，添加剩下的</span></span><br></pre></td></tr></table></figure>

<h3 id="23-合并-K-个升序链表"><a href="#23-合并-K-个升序链表" class="headerlink" title="23. 合并 K 个升序链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/merge-k-sorted-lists/?envType=study-plan-v2&id=top-100-liked">23. 合并 K 个升序链表</a></h3><p>连接为一个链表，再排序</p>
<h2 id="二叉树"><a href="#二叉树" class="headerlink" title="二叉树"></a><center>二叉树</center></h2><h3 id="94-二叉树的中序遍历"><a href="#94-二叉树的中序遍历" class="headerlink" title="94. 二叉树的中序遍历"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/binary-tree-inorder-traversal/?envType=study-plan-v2&id=top-100-liked">94. 二叉树的中序遍历</a></h3><p>递归语句放在中间</p>
<h3 id="104-二叉树的最大深度"><a href="#104-二叉树的最大深度" class="headerlink" title="104. 二叉树的最大深度"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/maximum-depth-of-binary-tree/?envType=study-plan-v2&id=top-100-liked">104. 二叉树的最大深度</a></h3><p>左右递归，<code>return Math.max(lefthead, righthead) + 1;</code></p>
<h3 id="226-翻转二叉树"><a href="#226-翻转二叉树" class="headerlink" title="226. 翻转二叉树"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/invert-binary-tree/">226. 翻转二叉树</a></h3><p>左右递归</p>
<h3 id="101-对称二叉树"><a href="#101-对称二叉树" class="headerlink" title="101. 对称二叉树"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/symmetric-tree/">101. 对称二叉树</a></h3><p>多层if，前面的if相当于过滤的作用</p>
<h3 id="543-二叉树的直径"><a href="#543-二叉树的直径" class="headerlink" title="543. 二叉树的直径"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/diameter-of-binary-tree/">543. 二叉树的直径</a></h3><p>转为二叉树的左右深度问题</p>
<h3 id="102-二叉树的层序遍历"><a href="#102-二叉树的层序遍历" class="headerlink" title="102. 二叉树的层序遍历"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/binary-tree-level-order-traversal/?envType=study-plan-v2&id=top-100-liked">102. 二叉树的层序遍历</a></h3><ul>
<li>队列</li>
<li>构造好返回类型</li>
</ul>
<h3 id="108-将有序数组转换为二叉搜索树"><a href="#108-将有序数组转换为二叉搜索树" class="headerlink" title="108. 将有序数组转换为二叉搜索树"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/?envType=study-plan-v2&id=top-100-liked">108. 将有序数组转换为二叉搜索树</a></h3><p>类似二分，中序顺序，一些辅助函数，经常将整个数组传进去，同时传入一些下标供操作</p>
<h3 id="98-验证二叉搜索树"><a href="#98-验证二叉搜索树" class="headerlink" title="98. 验证二叉搜索树"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/validate-binary-search-tree/">98. 验证二叉搜索树</a></h3><ul>
<li>对于每个子树而言，无论他是左子树下的右子子树，还是右子树下的左子子树，其中节点值都有范围限制的，递归的时候，动态调整范围大小，类似二分查找时，动态调整区间左右端点的意思</li>
<li><code>Long.MIN_VALUE</code> 包装类型加上全大写</li>
</ul>
<h3 id="230-二叉搜索树中第K小的元素"><a href="#230-二叉搜索树中第K小的元素" class="headerlink" title="230. 二叉搜索树中第K小的元素"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/kth-smallest-element-in-a-bst/">230. 二叉搜索树中第K小的元素</a></h3><p>利用中序遍历的特点，注意递归时的结束判断</p>
<h3 id="199-二叉树的右视图"><a href="#199-二叉树的右视图" class="headerlink" title="199. 二叉树的右视图"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/binary-tree-right-side-view/">199. 二叉树的右视图</a></h3><p>层序遍历</p>
<h3 id="114-二叉树展开为链表"><a href="#114-二叉树展开为链表" class="headerlink" title="114. 二叉树展开为链表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/?envType=study-plan-v2&id=top-100-liked">114. 二叉树展开为链表</a></h3><p><code>Queue</code>或者<code>List</code>存储顺序</p>
<h3 id="105-从前序与中序遍历序列构造二叉树"><a href="#105-从前序与中序遍历序列构造二叉树" class="headerlink" title="105. 从前序与中序遍历序列构造二叉树"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/">105. 从前序与中序遍历序列构造二叉树</a></h3><ul>
<li>递归时，将数组下标传入，方便操作，注意返回的构造</li>
<li>当数组元素不重复时，用 <strong>Map</strong> 建立数组下标的索引，方便快速查找数组下标</li>
</ul>
<h3 id="437-路径总和-III"><a href="#437-路径总和-III" class="headerlink" title="437. 路径总和 III"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/path-sum-iii/?envType=study-plan-v2&id=top-100-liked">437. 路径总和 III</a></h3><p>双递归，第一个递归用来遍历每个节点，在此基础上以每个节点为根节点，进行第二个递归，来实现相应的查找</p>
<h3 id="236-二叉树的最近公共祖先"><a href="#236-二叉树的最近公共祖先" class="headerlink" title="236. 二叉树的最近公共祖先"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-tree/">236. 二叉树的最近公共祖先</a></h3><p>后续遍历，从下到上判断，List保存符合要求的节点，第一个就是最近的祖先</p>
<h3 id="124-二叉树中的最大路径和"><a href="#124-二叉树中的最大路径和" class="headerlink" title="124. 二叉树中的最大路径和"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/binary-tree-maximum-path-sum/?envType=study-plan-v2&id=top-100-liked">124. 二叉树中的最大路径和</a></h3><p>双递归，一个用来遍历，一个用来找含当前节点的最大路径片段和</p>
<h2 id="图论"><a href="#图论" class="headerlink" title=" 图论"></a><center> 图论</center></h2><h3 id="200-岛屿数量"><a href="#200-岛屿数量" class="headerlink" title="200. 岛屿数量"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/number-of-islands/?envType=study-plan-v2&id=top-100-liked">200. 岛屿数量</a></h3><p>深度优先遍历：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">dfs</span><span class="params">(<span class="type">int</span>[][] grid, <span class="type">int</span> i, <span class="type">int</span> j)</span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(i&lt;<span class="number">0</span> || i&gt;=grid.length || j&lt;<span class="number">0</span> || j&gt;=grid[<span class="number">0</span>].length)<span class="keyword">return</span>; <span class="comment">//超出范围</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(grid[i][j] != <span class="number">1</span>) <span class="keyword">return</span>; <span class="comment">//非陆地，或已遍历的陆地</span></span><br><span class="line"></span><br><span class="line">    grid[i][j] = <span class="number">2</span>; <span class="comment">//标记已遍历陆地</span></span><br><span class="line"></span><br><span class="line">    dfs(grid,i-<span class="number">1</span>,j); <span class="comment">//上</span></span><br><span class="line">    dfs(grid,i+<span class="number">1</span>,j); <span class="comment">//下</span></span><br><span class="line">    dfs(grid,i,j-<span class="number">1</span>); <span class="comment">//左</span></span><br><span class="line">    dfs(grid,i,j+<span class="number">1</span>); <span class="comment">//右</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="207-课程表"><a href="#207-课程表" class="headerlink" title="207. 课程表"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/course-schedule/?envType=study-plan-v2&id=top-100-liked">207. 课程表</a></h3><ul>
<li><code>List&lt;List&lt;Integer&gt;&gt; adjacency = new LinkedList&lt;&gt;()</code> 建立邻接表，以及邻接表的初始化</li>
<li><code>入度</code>、<code>出度</code>的概念</li>
<li>建立<code>队列</code>辅助操作</li>
</ul>
<h3 id="994-腐烂的橘子"><a href="#994-腐烂的橘子" class="headerlink" title="994. 腐烂的橘子"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/rotting-oranges/">994. 腐烂的橘子</a></h3><p><code>广度优先</code>，找出所有待操作的值保存入<code>Queue</code>，对queue里面的值进行相应操作</p>
<h2 id="回溯"><a href="#回溯" class="headerlink" title=" 回溯"></a><center> 回溯</center></h2><h3 id="46-全排列"><a href="#46-全排列" class="headerlink" title="46. 全排列"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/permutations/?envType=study-plan-v2&id=top-100-liked">46. 全排列</a></h3><ul>
<li>引入标志位数组，已遍历置为1，回溯时还原为0</li>
</ul>
<h3 id="78-子集"><a href="#78-子集" class="headerlink" title="78. 子集"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/subsets/">78. 子集</a></h3><ol>
<li>所有的组合可以和二进制数形成对应关系，通过二进制数来排列<ul>
<li><code>左移运算符 &quot;&lt;&lt;&quot;</code> 2 &lt;&lt; 3 : 2 的二进制数<code>00000010</code>整体左移3位，高位舍弃，低位补0 ，变成 <code>00010000</code> 即为 16</li>
<li><code>带符号右移运算符 &quot;&lt;&lt;&quot;</code></li>
</ul>
<ol>
<li>7 &gt;&gt; 2 : 7 的二进制数<code>00000111</code>整体右移2位，7是正数，所以高位全补0，低位舍弃，变成<code>00000001</code> 即为1</li>
<li>-9 &gt;&gt; 2 : -9 的二进制数（补码）<code>1111 0111</code>整体右移2位，-9是负数，所以高位全补1，低位舍弃，变成<code>1111 1101</code> 即为 -3</li>
</ol>
<ul>
<li><code>无符号右移运算符 &quot;&lt;&lt;&lt;&quot;</code> 无论正负，高位全补0</li>
</ul>
</li>
<li>递归，数组每一位存在要或者不要两种情况，全局的 栈 或 list 保存递归过程的情况</li>
</ol>
<h3 id="17-电话号码的字母组合"><a href="#17-电话号码的字母组合" class="headerlink" title="17. 电话号码的字母组合"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/letter-combinations-of-a-phone-number/">17. 电话号码的字母组合</a></h3><p>递归，依次遍历</p>
<h3 id="39-组合总和"><a href="#39-组合总和" class="headerlink" title="39. 组合总和"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/combination-sum/">39. 组合总和</a></h3><ul>
<li><code>排序</code>， 避免重复问题的常用 预处理 办法</li>
<li>回溯就用 <strong>栈</strong></li>
</ul>
<h3 id="22-括号生成"><a href="#22-括号生成" class="headerlink" title="22. 括号生成"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/generate-parentheses/">22. 括号生成</a></h3><p>不要用全局string，就递归生成string，到最后判断</p>
<h3 id="79-单词搜索"><a href="#79-单词搜索" class="headerlink" title="79. 单词搜索"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/word-search/">79. 单词搜索</a></h3><p>关键在于数据的标记，用一个临时变量保存这个数据，在递归后，恢复这个数据，就相当于原数据矩阵没有被破坏，</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">char</span> <span class="variable">tmp</span> <span class="operator">=</span> board[i][j];</span><br><span class="line">board[i][j] = <span class="string">&#x27;#&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="type">boolean</span> <span class="variable">exist</span> <span class="operator">=</span> dfs(board, i - <span class="number">1</span>, j, index + <span class="number">1</span>) ||</span><br><span class="line">                dfs(board, i + <span class="number">1</span>, j, index + <span class="number">1</span>) ||</span><br><span class="line">                dfs(board, i, j - <span class="number">1</span>, index + <span class="number">1</span>) ||</span><br><span class="line">                dfs(board, i, j + <span class="number">1</span>, index + <span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">board[i][j] = tmp;</span><br><span class="line"><span class="comment">// 恢复数据，在当前递归层，只要数据恢复了，</span></span><br><span class="line"><span class="comment">// 那对于上一层的递归来说，结束一个方向的递归调用后，矩阵数据还是“干净”的，再往另一个方向递归不受影响</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">return</span> exist;</span><br></pre></td></tr></table></figure>

<h3 id="131-分割回文串"><a href="#131-分割回文串" class="headerlink" title="131. 分割回文串"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/palindrome-partitioning/?envType=study-plan-v2&envId=top-100-liked">131. 分割回文串</a></h3><p>回溯和栈关系密切，在dfs里面循环，注意递归后注意恢复，也就是所谓的回溯</p>
<h2 id="二分查找"><a href="#二分查找" class="headerlink" title=" 二分查找"></a><center> 二分查找</center></h2><h3 id="35-搜索插入位置"><a href="#35-搜索插入位置" class="headerlink" title="35. 搜索插入位置"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/search-insert-position/">35. 搜索插入位置</a></h3><ul>
<li><code>mid</code>的值要用 <code>((right - left) &gt;&gt; 1) + left</code> 计算</li>
</ul>
<h3 id="74-搜索二维矩阵"><a href="#74-搜索二维矩阵" class="headerlink" title="74. 搜索二维矩阵"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/search-a-2d-matrix/">74. 搜索二维矩阵</a></h3><p>次对角线搜索，Z字形</p>
<h3 id="34-在排序数组中查找元素的第一个和最后一个位置"><a href="#34-在排序数组中查找元素的第一个和最后一个位置" class="headerlink" title="34. 在排序数组中查找元素的第一个和最后一个位置"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/">34. 在排序数组中查找元素的第一个和最后一个位置</a></h3><p>二分递归</p>
<h3 id="33-搜索旋转排序数组"><a href="#33-搜索旋转排序数组" class="headerlink" title="33. 搜索旋转排序数组"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/search-in-rotated-sorted-array/">33. 搜索旋转排序数组</a></h3><p>画图，分好类</p>
<h3 id="153-寻找旋转排序数组中的最小值"><a href="#153-寻找旋转排序数组中的最小值" class="headerlink" title="153. 寻找旋转排序数组中的最小值"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/">153. 寻找旋转排序数组中的最小值</a></h3><p>画图</p>
<h2 id="栈"><a href="#栈" class="headerlink" title=" 栈"></a><center> 栈</center></h2><h3 id="20-有效的括号"><a href="#20-有效的括号" class="headerlink" title="20. 有效的括号"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/valid-parentheses/">20. 有效的括号</a></h3><ul>
<li>栈</li>
<li>遇到左括号就把右括号放进去，遇到右括号，弹出栈顶元素，判断是否相同字符</li>
</ul>
<h3 id="394-字符串解码"><a href="#394-字符串解码" class="headerlink" title="394. 字符串解码"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/decode-string/?envType=study-plan-v2&envId=top-100-liked">394. 字符串解码</a></h3><ul>
<li>模拟过程</li>
<li>连续字符还原数字注意引入倍数</li>
</ul>
<h3 id="739-每日温度"><a href="#739-每日温度" class="headerlink" title="739. 每日温度"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/daily-temperatures/?envType=study-plan-v2&envId=top-100-liked">739. 每日温度</a></h3><p>温度只是表象，重点操作背后的下标，也就是对应的时间，温度只是用来比较</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; len; i++) &#123;</span><br><span class="line">    <span class="keyword">while</span> (!stack.isEmpty() &amp;&amp; temperatures[i] &gt; temperatures[stack.peek()]) &#123;</span><br><span class="line">        res[stack.peek()] = i;</span><br><span class="line">        stack.pop();</span><br><span class="line">    &#125;</span><br><span class="line">    stack.push(i);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>关键逻辑：对于temperatures数组：要是当前第<code>i</code>个temperatures值 比 栈顶存放的 下标(假设为<code>j</code>)对应的temperatures值 大，则把栈顶的 <code>j</code> 弹出来，以这个<code>j</code>为索引，在辅助数组res里面把res[<code>j</code>]的值赋为<code>i</code>。</p>
<p>即：res[k]存放的是比temperatures[k]大的下一个temperatures值的<code>下标</code></p>
<p>这里，for正向遍历temperatures，从左向右维护一个的单调栈，也可以调整for循环的方向，实现从右向左的单调栈，同时，可以调整while的判断逻辑，寻相应下一个大或者小的值。</p>
<h3 id="84-柱状图中最大的矩形"><a href="#84-柱状图中最大的矩形" class="headerlink" title="84. 柱状图中最大的矩形"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/largest-rectangle-in-histogram/">84. 柱状图中最大的矩形</a></h3><p>融合了<code>接雨水</code>和<code>每日温度</code>，思路是接雨水，技巧是每日温度的单调栈：<br>对于每个高度，求出其左右两边最近的、比自己小的数的下标，放进两个数组，遍历两个左右数组，求所夹的最小矩形面积</p>
<h2 id="堆"><a href="#堆" class="headerlink" title=" 堆"></a><center> 堆</center></h2><h3 id="215-数组中的第K个最大元素"><a href="#215-数组中的第K个最大元素" class="headerlink" title="215. 数组中的第K个最大元素"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/kth-largest-element-in-an-array/?envType=study-plan-v2&envId=top-100-liked">215. 数组中的第K个最大元素</a></h3><p><code>PriorityQueue&lt;Integer&gt; pq = new PriorityQueue&lt;&gt;((a,b) -&gt; &#123;return b - a;&#125;);</code></p>
<h3 id="347-前-K-个高频元素"><a href="#347-前-K-个高频元素" class="headerlink" title="347. 前 K 个高频元素"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/top-k-frequent-elements/?envType=study-plan-v2&envId=top-100-liked">347. 前 K 个高频元素</a></h3><ul>
<li><code>PriorityQueue&lt;Integer&gt; pq = new PriorityQueue&lt;&gt;((a,b) -&gt; &#123;return map.get(b) - map.get(a);&#125;);</code></li>
<li><code>hashmap.getOrDefault(Object key, V defaultValue)</code> 获取指定 key 对应对 value，如果找不到 key ，则返回设置的默认值。</li>
</ul>
<h2 id="贪心算法"><a href="#贪心算法" class="headerlink" title=" 贪心算法"></a><center> 贪心算法</center></h2><h3 id="121-买卖股票的最佳时机"><a href="#121-买卖股票的最佳时机" class="headerlink" title="121. 买卖股票的最佳时机"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/?envType=study-plan-v2&envId=top-100-liked">121. 买卖股票的最佳时机</a></h3><p>对于当前价格，去找之前的最小价格（这个最小可以随遍历动态更新），求出一个利润，遍历所有价格，求出所有利润，这个过程动态更新最大利润</p>
<h3 id="55-跳跃游戏"><a href="#55-跳跃游戏" class="headerlink" title="55. 跳跃游戏"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/jump-game/?envType=study-plan-v2&envId=top-100-liked">55. 跳跃游戏</a></h3><h3 id="45-跳跃游戏-II"><a href="#45-跳跃游戏-II" class="headerlink" title="45. 跳跃游戏 II"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/jump-game-ii/?envType=study-plan-v2&envId=top-100-liked">45. 跳跃游戏 II</a></h3><p>这两个跳跃，都可以用最远距离的思想来做 <code>maxdistance = Math.max(maxdistance, i + nums[i])</code> ，用数组第1个数字，求出<code>第1个最远距离</code>，在下标<code>0 ~ 第1个最远距离</code>内，遍历所有值，更新出<code>第2个最远距离</code>，在<code>第1个最远距离 + 1 ~ 第2个最远距离</code>内，遍历所有值，更新出<code>第3个最远距离</code>…，以此类推，可以用嵌套循环实现</p>
<h3 id="763-划分字母区间"><a href="#763-划分字母区间" class="headerlink" title="763. 划分字母区间"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/partition-labels/">763. 划分字母区间</a></h3><p>用字典保存字符串字母数据，随着遍历，如果当前set内字母在后面都不会出现，即都已经用完了，就导出一次结果</p>
<h2 id="动态规划"><a href="#动态规划" class="headerlink" title=" 动态规划"></a><center> 动态规划</center></h2><h3 id="70-爬楼梯"><a href="#70-爬楼梯" class="headerlink" title="70. 爬楼梯"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/climbing-stairs/?envType=study-plan-v2&envId=top-100-liked">70. 爬楼梯</a></h3><p>爬完n个台阶的方式只有两种：爬完n-1个台阶再爬一个、或者爬完n-2个再爬2个。那对应的总方式就是 爬完n-1个的总方式 加上 爬完n-2个的总方式</p>
<h3 id="118-杨辉三角"><a href="#118-杨辉三角" class="headerlink" title="118. 杨辉三角"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/pascals-triangle/?envType=study-plan-v2&envId=top-100-liked">118. 杨辉三角</a></h3><p>考虑上下的依赖关系，倒着更新</p>
<h3 id="198-打家劫舍"><a href="#198-打家劫舍" class="headerlink" title="198. 打家劫舍"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/house-robber/">198. 打家劫舍</a></h3><p>子问题，两种偷法：如果<code>不偷第i家</code>，则dp[i] &#x3D; dp[i-1]、如果<code>偷第i家</code>，则dp[i] &#x3D; dp[i-2] + 第i家的钱</p>
<h2 id="技巧"><a href="#技巧" class="headerlink" title=" 技巧"></a><center> 技巧</center></h2><h3 id="136-只出现一次的数字"><a href="#136-只出现一次的数字" class="headerlink" title="136. 只出现一次的数字"></a><a target="_blank" rel="noopener" href="https://leetcode.cn/problems/single-number/">136. 只出现一次的数字</a></h3><p><code>异或</code>运算 $\bigoplus$：相同为0，不同为1<br>    - 任何数和0做异或运算，结果仍然是原来的数，即：a $\bigoplus$ 0 &#x3D; a;<br>    - 任何数和其自身做异或运算，结果是：a $\bigoplus$ a &#x3D; 0;<br>    - 异或运算满足交换律和结合律，即：a⊕b⊕a&#x3D;b⊕a⊕a&#x3D;b⊕(a⊕a)&#x3D;b⊕0&#x3D;b。</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://jingxiao-yz.github.io">jingxiao</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://jingxiao-yz.github.io/2023/05/04/LeetCode-Hot-100/">https://jingxiao-yz.github.io/2023/05/04/LeetCode-Hot-100/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://jingxiao-yz.github.io" target="_blank">jingxiao's space</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="/img/default_cover.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/2023/05/09/aboutstream/" title="从 FileInputStream.read() 到 Windows api ReadFile()"><img class="cover" src="/img/default_cover.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">从 FileInputStream.read() 到 Windows api ReadFile()</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/head.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">jingxiao</div><div class="author-info__description">记录一哈</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">3</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/jingxiao-yz"><i class="fab fa-github"></i><span>戳我</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">我来啦！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#LeetCode-%E7%83%AD%E9%A2%98-100"><span class="toc-number">1.</span> <span class="toc-text"> LeetCode 热题 100</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%93%88%E5%B8%8C"><span class="toc-number">1.1.</span> <span class="toc-text">哈希</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E4%B8%A4%E6%95%B0%E4%B9%8B%E5%92%8C"><span class="toc-number">1.1.1.</span> <span class="toc-text">1. 两数之和</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#49-%E5%AD%97%E6%AF%8D%E5%BC%82%E4%BD%8D%E8%AF%8D%E5%88%86%E7%BB%84"><span class="toc-number">1.1.2.</span> <span class="toc-text">49. 字母异位词分组</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#128-%E6%9C%80%E9%95%BF%E8%BF%9E%E7%BB%AD%E5%BA%8F%E5%88%97"><span class="toc-number">1.1.3.</span> <span class="toc-text">128. 最长连续序列</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%8C%E6%8C%87%E9%92%88"><span class="toc-number">1.2.</span> <span class="toc-text">双指针</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#15-%E4%B8%89%E6%95%B0%E4%B9%8B%E5%92%8C"><span class="toc-number">1.2.1.</span> <span class="toc-text">15. 三数之和</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#283-%E7%A7%BB%E5%8A%A8%E9%9B%B6"><span class="toc-number">1.2.2.</span> <span class="toc-text">283. 移动零</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#11-%E7%9B%9B%E6%9C%80%E5%A4%9A%E6%B0%B4%E7%9A%84%E5%AE%B9%E5%99%A8"><span class="toc-number">1.2.3.</span> <span class="toc-text">11. 盛最多水的容器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#42-%E6%8E%A5%E9%9B%A8%E6%B0%B4"><span class="toc-number">1.2.4.</span> <span class="toc-text">42. 接雨水</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3"><span class="toc-number">1.3.</span> <span class="toc-text">滑动窗口</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E6%97%A0%E9%87%8D%E5%A4%8D%E5%AD%97%E7%AC%A6%E7%9A%84%E6%9C%80%E9%95%BF%E5%AD%90%E4%B8%B2"><span class="toc-number">1.3.1.</span> <span class="toc-text">3. 无重复字符的最长子串</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#438-%E6%89%BE%E5%88%B0%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E6%89%80%E6%9C%89%E5%AD%97%E6%AF%8D%E5%BC%82%E4%BD%8D%E8%AF%8D"><span class="toc-number">1.3.2.</span> <span class="toc-text">438. 找到字符串中所有字母异位词</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%97%E4%B8%B2"><span class="toc-number">1.4.</span> <span class="toc-text">字串</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#239-%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%E6%9C%80%E5%A4%A7%E5%80%BC"><span class="toc-number">1.4.1.</span> <span class="toc-text">239. 滑动窗口最大值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#560-%E5%92%8C%E4%B8%BA-K-%E7%9A%84%E5%AD%90%E6%95%B0%E7%BB%84"><span class="toc-number">1.4.2.</span> <span class="toc-text">560. 和为 K 的子数组</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%99%AE%E9%80%9A%E6%95%B0%E7%BB%84"><span class="toc-number">1.5.</span> <span class="toc-text">普通数组</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#53-%E6%9C%80%E5%A4%A7%E5%AD%90%E6%95%B0%E7%BB%84%E5%92%8C"><span class="toc-number">1.5.1.</span> <span class="toc-text">53. 最大子数组和</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#56-%E5%90%88%E5%B9%B6%E5%8C%BA%E9%97%B4"><span class="toc-number">1.5.2.</span> <span class="toc-text">56. 合并区间</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#189-%E8%BD%AE%E8%BD%AC%E6%95%B0%E7%BB%84"><span class="toc-number">1.5.3.</span> <span class="toc-text">189. 轮转数组</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#238-%E9%99%A4%E8%87%AA%E8%BA%AB%E4%BB%A5%E5%A4%96%E6%95%B0%E7%BB%84%E7%9A%84%E4%B9%98%E7%A7%AF"><span class="toc-number">1.5.4.</span> <span class="toc-text">238. 除自身以外数组的乘积</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9F%A9%E9%98%B5"><span class="toc-number">1.6.</span> <span class="toc-text">矩阵</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#73-%E7%9F%A9%E9%98%B5%E7%BD%AE%E9%9B%B6"><span class="toc-number">1.6.1.</span> <span class="toc-text">73. 矩阵置零</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#54-%E8%9E%BA%E6%97%8B%E7%9F%A9%E9%98%B5"><span class="toc-number">1.6.2.</span> <span class="toc-text">54. 螺旋矩阵</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#48-%E6%97%8B%E8%BD%AC%E5%9B%BE%E5%83%8F"><span class="toc-number">1.6.3.</span> <span class="toc-text">48. 旋转图像</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#240-%E6%90%9C%E7%B4%A2%E4%BA%8C%E7%BB%B4%E7%9F%A9%E9%98%B5-II"><span class="toc-number">1.6.4.</span> <span class="toc-text">240. 搜索二维矩阵 II</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.</span> <span class="toc-text">链表</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#160-%E7%9B%B8%E4%BA%A4%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.1.</span> <span class="toc-text">160. 相交链表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#206-%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.2.</span> <span class="toc-text">206. 反转链表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#234-%E5%9B%9E%E6%96%87%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.3.</span> <span class="toc-text">234. 回文链表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#141-%E7%8E%AF%E5%BD%A2%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.4.</span> <span class="toc-text">141. 环形链表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#142-%E7%8E%AF%E5%BD%A2%E9%93%BE%E8%A1%A8-II"><span class="toc-number">1.7.5.</span> <span class="toc-text">142. 环形链表 II</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#21-%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%9C%89%E5%BA%8F%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.6.</span> <span class="toc-text">21. 合并两个有序链表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E4%B8%A4%E6%95%B0%E7%9B%B8%E5%8A%A0"><span class="toc-number">1.7.7.</span> <span class="toc-text">2. 两数相加</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#19-%E5%88%A0%E9%99%A4%E9%93%BE%E8%A1%A8%E7%9A%84%E5%80%92%E6%95%B0%E7%AC%AC-N-%E4%B8%AA%E7%BB%93%E7%82%B9"><span class="toc-number">1.7.8.</span> <span class="toc-text">19. 删除链表的倒数第 N 个结点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#24-%E4%B8%A4%E4%B8%A4%E4%BA%A4%E6%8D%A2%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9"><span class="toc-number">1.7.9.</span> <span class="toc-text">24. 两两交换链表中的节点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#25-K-%E4%B8%AA%E4%B8%80%E7%BB%84%E7%BF%BB%E8%BD%AC%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.10.</span> <span class="toc-text">25. K 个一组翻转链表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#138-%E5%A4%8D%E5%88%B6%E5%B8%A6%E9%9A%8F%E6%9C%BA%E6%8C%87%E9%92%88%E7%9A%84%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.11.</span> <span class="toc-text">138. 复制带随机指针的链表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#148-%E6%8E%92%E5%BA%8F%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.12.</span> <span class="toc-text">148. 排序链表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#23-%E5%90%88%E5%B9%B6-K-%E4%B8%AA%E5%8D%87%E5%BA%8F%E9%93%BE%E8%A1%A8"><span class="toc-number">1.7.13.</span> <span class="toc-text">23. 合并 K 个升序链表</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E5%8F%89%E6%A0%91"><span class="toc-number">1.8.</span> <span class="toc-text">二叉树</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#94-%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86"><span class="toc-number">1.8.1.</span> <span class="toc-text">94. 二叉树的中序遍历</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#104-%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%9C%80%E5%A4%A7%E6%B7%B1%E5%BA%A6"><span class="toc-number">1.8.2.</span> <span class="toc-text">104. 二叉树的最大深度</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#226-%E7%BF%BB%E8%BD%AC%E4%BA%8C%E5%8F%89%E6%A0%91"><span class="toc-number">1.8.3.</span> <span class="toc-text">226. 翻转二叉树</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#101-%E5%AF%B9%E7%A7%B0%E4%BA%8C%E5%8F%89%E6%A0%91"><span class="toc-number">1.8.4.</span> <span class="toc-text">101. 对称二叉树</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#543-%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E7%9B%B4%E5%BE%84"><span class="toc-number">1.8.5.</span> <span class="toc-text">543. 二叉树的直径</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#102-%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E5%B1%82%E5%BA%8F%E9%81%8D%E5%8E%86"><span class="toc-number">1.8.6.</span> <span class="toc-text">102. 二叉树的层序遍历</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#108-%E5%B0%86%E6%9C%89%E5%BA%8F%E6%95%B0%E7%BB%84%E8%BD%AC%E6%8D%A2%E4%B8%BA%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91"><span class="toc-number">1.8.7.</span> <span class="toc-text">108. 将有序数组转换为二叉搜索树</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#98-%E9%AA%8C%E8%AF%81%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91"><span class="toc-number">1.8.8.</span> <span class="toc-text">98. 验证二叉搜索树</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#230-%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E4%B8%AD%E7%AC%ACK%E5%B0%8F%E7%9A%84%E5%85%83%E7%B4%A0"><span class="toc-number">1.8.9.</span> <span class="toc-text">230. 二叉搜索树中第K小的元素</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#199-%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E5%8F%B3%E8%A7%86%E5%9B%BE"><span class="toc-number">1.8.10.</span> <span class="toc-text">199. 二叉树的右视图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#114-%E4%BA%8C%E5%8F%89%E6%A0%91%E5%B1%95%E5%BC%80%E4%B8%BA%E9%93%BE%E8%A1%A8"><span class="toc-number">1.8.11.</span> <span class="toc-text">114. 二叉树展开为链表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#105-%E4%BB%8E%E5%89%8D%E5%BA%8F%E4%B8%8E%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E5%BA%8F%E5%88%97%E6%9E%84%E9%80%A0%E4%BA%8C%E5%8F%89%E6%A0%91"><span class="toc-number">1.8.12.</span> <span class="toc-text">105. 从前序与中序遍历序列构造二叉树</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#437-%E8%B7%AF%E5%BE%84%E6%80%BB%E5%92%8C-III"><span class="toc-number">1.8.13.</span> <span class="toc-text">437. 路径总和 III</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#236-%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88"><span class="toc-number">1.8.14.</span> <span class="toc-text">236. 二叉树的最近公共祖先</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#124-%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%AD%E7%9A%84%E6%9C%80%E5%A4%A7%E8%B7%AF%E5%BE%84%E5%92%8C"><span class="toc-number">1.8.15.</span> <span class="toc-text">124. 二叉树中的最大路径和</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%BE%E8%AE%BA"><span class="toc-number">1.9.</span> <span class="toc-text"> 图论</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#200-%E5%B2%9B%E5%B1%BF%E6%95%B0%E9%87%8F"><span class="toc-number">1.9.1.</span> <span class="toc-text">200. 岛屿数量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#207-%E8%AF%BE%E7%A8%8B%E8%A1%A8"><span class="toc-number">1.9.2.</span> <span class="toc-text">207. 课程表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#994-%E8%85%90%E7%83%82%E7%9A%84%E6%A9%98%E5%AD%90"><span class="toc-number">1.9.3.</span> <span class="toc-text">994. 腐烂的橘子</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9E%E6%BA%AF"><span class="toc-number">1.10.</span> <span class="toc-text"> 回溯</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#46-%E5%85%A8%E6%8E%92%E5%88%97"><span class="toc-number">1.10.1.</span> <span class="toc-text">46. 全排列</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#78-%E5%AD%90%E9%9B%86"><span class="toc-number">1.10.2.</span> <span class="toc-text">78. 子集</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#17-%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81%E7%9A%84%E5%AD%97%E6%AF%8D%E7%BB%84%E5%90%88"><span class="toc-number">1.10.3.</span> <span class="toc-text">17. 电话号码的字母组合</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#39-%E7%BB%84%E5%90%88%E6%80%BB%E5%92%8C"><span class="toc-number">1.10.4.</span> <span class="toc-text">39. 组合总和</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#22-%E6%8B%AC%E5%8F%B7%E7%94%9F%E6%88%90"><span class="toc-number">1.10.5.</span> <span class="toc-text">22. 括号生成</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#79-%E5%8D%95%E8%AF%8D%E6%90%9C%E7%B4%A2"><span class="toc-number">1.10.6.</span> <span class="toc-text">79. 单词搜索</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#131-%E5%88%86%E5%89%B2%E5%9B%9E%E6%96%87%E4%B8%B2"><span class="toc-number">1.10.7.</span> <span class="toc-text">131. 分割回文串</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE"><span class="toc-number">1.11.</span> <span class="toc-text"> 二分查找</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#35-%E6%90%9C%E7%B4%A2%E6%8F%92%E5%85%A5%E4%BD%8D%E7%BD%AE"><span class="toc-number">1.11.1.</span> <span class="toc-text">35. 搜索插入位置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#74-%E6%90%9C%E7%B4%A2%E4%BA%8C%E7%BB%B4%E7%9F%A9%E9%98%B5"><span class="toc-number">1.11.2.</span> <span class="toc-text">74. 搜索二维矩阵</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#34-%E5%9C%A8%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%92%8C%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E4%BD%8D%E7%BD%AE"><span class="toc-number">1.11.3.</span> <span class="toc-text">34. 在排序数组中查找元素的第一个和最后一个位置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#33-%E6%90%9C%E7%B4%A2%E6%97%8B%E8%BD%AC%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84"><span class="toc-number">1.11.4.</span> <span class="toc-text">33. 搜索旋转排序数组</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#153-%E5%AF%BB%E6%89%BE%E6%97%8B%E8%BD%AC%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%9C%80%E5%B0%8F%E5%80%BC"><span class="toc-number">1.11.5.</span> <span class="toc-text">153. 寻找旋转排序数组中的最小值</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A0%88"><span class="toc-number">1.12.</span> <span class="toc-text"> 栈</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#20-%E6%9C%89%E6%95%88%E7%9A%84%E6%8B%AC%E5%8F%B7"><span class="toc-number">1.12.1.</span> <span class="toc-text">20. 有效的括号</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#394-%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%A7%A3%E7%A0%81"><span class="toc-number">1.12.2.</span> <span class="toc-text">394. 字符串解码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#739-%E6%AF%8F%E6%97%A5%E6%B8%A9%E5%BA%A6"><span class="toc-number">1.12.3.</span> <span class="toc-text">739. 每日温度</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#84-%E6%9F%B1%E7%8A%B6%E5%9B%BE%E4%B8%AD%E6%9C%80%E5%A4%A7%E7%9A%84%E7%9F%A9%E5%BD%A2"><span class="toc-number">1.12.4.</span> <span class="toc-text">84. 柱状图中最大的矩形</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A0%86"><span class="toc-number">1.13.</span> <span class="toc-text"> 堆</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#215-%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E7%AC%ACK%E4%B8%AA%E6%9C%80%E5%A4%A7%E5%85%83%E7%B4%A0"><span class="toc-number">1.13.1.</span> <span class="toc-text">215. 数组中的第K个最大元素</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#347-%E5%89%8D-K-%E4%B8%AA%E9%AB%98%E9%A2%91%E5%85%83%E7%B4%A0"><span class="toc-number">1.13.2.</span> <span class="toc-text">347. 前 K 个高频元素</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B4%AA%E5%BF%83%E7%AE%97%E6%B3%95"><span class="toc-number">1.14.</span> <span class="toc-text"> 贪心算法</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#121-%E4%B9%B0%E5%8D%96%E8%82%A1%E7%A5%A8%E7%9A%84%E6%9C%80%E4%BD%B3%E6%97%B6%E6%9C%BA"><span class="toc-number">1.14.1.</span> <span class="toc-text">121. 买卖股票的最佳时机</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#55-%E8%B7%B3%E8%B7%83%E6%B8%B8%E6%88%8F"><span class="toc-number">1.14.2.</span> <span class="toc-text">55. 跳跃游戏</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#45-%E8%B7%B3%E8%B7%83%E6%B8%B8%E6%88%8F-II"><span class="toc-number">1.14.3.</span> <span class="toc-text">45. 跳跃游戏 II</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#763-%E5%88%92%E5%88%86%E5%AD%97%E6%AF%8D%E5%8C%BA%E9%97%B4"><span class="toc-number">1.14.4.</span> <span class="toc-text">763. 划分字母区间</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92"><span class="toc-number">1.15.</span> <span class="toc-text"> 动态规划</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#70-%E7%88%AC%E6%A5%BC%E6%A2%AF"><span class="toc-number">1.15.1.</span> <span class="toc-text">70. 爬楼梯</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#118-%E6%9D%A8%E8%BE%89%E4%B8%89%E8%A7%92"><span class="toc-number">1.15.2.</span> <span class="toc-text">118. 杨辉三角</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#198-%E6%89%93%E5%AE%B6%E5%8A%AB%E8%88%8D"><span class="toc-number">1.15.3.</span> <span class="toc-text">198. 打家劫舍</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8A%80%E5%B7%A7"><span class="toc-number">1.16.</span> <span class="toc-text"> 技巧</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#136-%E5%8F%AA%E5%87%BA%E7%8E%B0%E4%B8%80%E6%AC%A1%E7%9A%84%E6%95%B0%E5%AD%97"><span class="toc-number">1.16.1.</span> <span class="toc-text">136. 只出现一次的数字</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/06/06/offer100/" title="剑指offer"><img src="/img/default_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="剑指offer"/></a><div class="content"><a class="title" href="/2023/06/06/offer100/" title="剑指offer">剑指offer</a><time datetime="2023-06-06T10:30:42.000Z" title="发表于 2023-06-06 18:30:42">2023-06-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/05/09/aboutstream/" title="从 FileInputStream.read() 到 Windows api ReadFile()"><img src="/img/default_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="从 FileInputStream.read() 到 Windows api ReadFile()"/></a><div class="content"><a class="title" href="/2023/05/09/aboutstream/" title="从 FileInputStream.read() 到 Windows api ReadFile()">从 FileInputStream.read() 到 Windows api ReadFile()</a><time datetime="2023-05-09T12:09:14.000Z" title="发表于 2023-05-09 20:09:14">2023-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/05/04/LeetCode-Hot-100/" title="LeetCode_Hot_100"><img src="/img/default_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="LeetCode_Hot_100"/></a><div class="content"><a class="title" href="/2023/05/04/LeetCode-Hot-100/" title="LeetCode_Hot_100">LeetCode_Hot_100</a><time datetime="2023-05-04T12:14:51.000Z" title="发表于 2023-05-04 20:14:51">2023-05-04</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By jingxiao</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><canvas class="fireworks" mobile="true"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/fireworks.min.js"></script><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="true" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>